<template>
<!-- 医师审核 医疗 -->
    <div>
        <div class="topsubmint el-col el-col-21">医师审核
            <el-button style="float: right; margin-right:50px;" type="primary" @click="submitForm">提交</el-button>
    
        </div>
        <el-card class="box-card">
            <div slot="header" class="card-heaer">
                <span style="line-height: 36px;">医师审核</span>
    
            </div>
    
            <div class="space20">
            </div>
            <div>
                <el-form label-width="100px">
                    <el-row type="flex" class="row-bg">
                        <el-col :span="5">
    
                            <el-form-item label="医院名称:">
                                <el-input v-model="BILL_HISPOTAL" placeholder="医院名称" :disabled="true"></el-input>
                            </el-form-item>
    
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="疾病名称:">
                                <el-input v-model="BILL_DISEASE" placeholder="疾病名称" :disabled="true"></el-input>
                            </el-form-item>
                        </el-col>
    
                        <el-col :span="6">
                            <el-form-item label="疾病详情:">
                                <el-input v-model="BILL_DISEASEDETAIL" type="textarea" :disabled="true" placeholder="疾病详情"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6" :offset="1">
                            <el-button type="primary" @click="dowload">
    
                                下载附件</el-button>
                        </el-col>
                    </el-row>
                </el-form>
    
                <div class="space20">
                </div>
                <el-form label-width="80px">
                    <el-form-item label="审核">
                        <el-select placeholder="审核" style="padding-left:20px;" v-model="BILL_STATE">
                            <el-option label="审核通过" value="需计算"></el-option>
                            <el-option label="退回重新填写" value="需理赔修改"></el-option>
                            <el-option label="拒赔" value="理赔审核不通过"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="修改原因" v-show="BILL_STATE=='需理赔修改'">
                        <el-input v-model="BILL_WHY" type="textarea" style="width:500px"></el-input>
                    </el-form-item>
                    <el-form-item label="拒赔原因" v-show="BILL_STATE=='理赔审核不通过'">
                        <el-input v-model="BILL_WHY" type="textarea" style="width:500px"></el-input>
                    </el-form-item>
    
                </el-form>
    
            </div>
            <div class="space20">
            </div>
            <el-collapse v-if="this.bill.length > 0">
                <el-collapse-item :title="data.BILL_DATA_DATA+'账单'" :key="data.BILL_DATA_DATA" v-for="(data, index) in bill ">
    
                    <el-card class="box-card">
                        <div slot="header" class="card-heaer">
                            <span style="line-height: 36px;">{{data.BILL_DATA_DATA}}账单</span>
    
                        </div>
                        <el-form label-width="200px">
                            <el-row type="flex" class="row-bg">
    
                                <el-col :span="8">
                                    <el-form-item label="医院类型:">
                                        <el-radio-group v-model="data.BILL_DATA_TYPE" :disabled="true">
                                            <el-radio label="网络内"></el-radio>
                                            <el-radio label="网络外"></el-radio>
                                        </el-radio-group>
                                    </el-form-item>
                                </el-col>
                                  <el-col :offset="2" :span="8">
                                 <el-form-item label="是否紧急情况:">
                                    <el-radio-group v-model="data.BILL_DATA_URGENCY" >
                                        <el-radio label="是"></el-radio>
                                        <el-radio label="否"></el-radio>
                                    </el-radio-group>
                                </el-form-item>
                                </el-col>
                                <!-- <el-col :span="8">
                                    <el-form-item>
                                        如若判定为紧急情况,可改为网络内医院!
                                    </el-form-item>
                                </el-col> -->
                            </el-row>
                        </el-form>
                        <div class="space20">
                        </div>
                        <lipeicheck_item :billdataid="index" ref="dataform">
                        </lipeicheck_item>
                    </el-card>
                </el-collapse-item>
            </el-collapse>
    
            </el-collapse>
        </el-card>
    </div>
</template>
<script>
import {
    mapState
} from 'vuex';
import getid from '@/js/getid';
import lipeicheck_item from '@/components/lipei/lipeicheck_item'
export default {
    data() {
        return {
            addtime: "",
            BILL_ID: "",
            file: "",
            BILL_STATE: "",
            BILL_WHY: "",
            whyshow: false,
            BILL_DISEASE: "",
            BILL_DISEASEDETAIL: "",
            BILL_HISPOTAL: ""

        };
    },
    watch: {
        'BILL_STATE': 'showwhy'
    },
    components: {
        'lipeicheck_item': lipeicheck_item
    },
    computed: mapState({
        bill: state => state.bill.bill
    }),

    methods: {
        showwhy() {
            if (this.BILL_STATE == "需修改" || this.BILL_STATE == "审核不通过") {
                this.whyshow = true;
            } else {
                this.whyshow = false;
            }
        },
        dowload() {
            var url = this.$http.options.root;
            var base = url.substring(0, url.length - 3);
            window.open(base + "Upload/" + this.file);
        },
        // length() {
        //     if (this.bill.length > 0) {
        //         for (var i = 0; i < this.bill.length; i++) {
        //             var detail = this.bill[i].BILL_DATA_DETAIL;
        //             var detlength = 0;
        //             for (var k = 0; k < detail.length; k++) {
        //                 if (detail[k].BILL_DATA_DETAIL_STATE != "删除") {
        //                     detlength++;
        //                 }
        //                 if (k == detail.length - 1 && detlength == 0) {
        //                     return false;
        //                 }
        //             }
        //             if (i == this.bill.length - 1) {
        //                 return true;
        //             }
        //         }
        //     } else {
        //         return false;
        //     }
        // },
        submitForm() {
            if (this.BILL_STATE == "" || this.BILL_STATE == null) {
                this.$notify.error({
                    title: '您还没有审核',
                    message: '您还没有审核',
                });
                return;
            } else {
                if ((this.BILL_WHY == "" || this.BILL_WHY == null) && this.BILL_STATE != "需计算") {
                    this.$notify.error({
                        title: '您没有填写原因',
                        message: '您没有填写原因',
                    });
                    return;
                }
            }
            var data = {
                BILL_ID: this.BILL_ID,
                BILL_DATA: this.bill,
                BILL_STATE: this.BILL_STATE,
                BILL_WHY: this.BILL_WHY
            }
            this.$http.put("Bill", data).then(response => {
                var data = response.body;

                if (data.code == 1) {
                    this.bill = [];
                    this.$notify({
                        title: '审核成功',
                        message: '审核成功',
                        type: 'success'
                    });
                    this.bill.splice(0, this.bill.length);
                    this.$router.push({
                        name: 'yishicheck'
                    });

                } else {
                    this.loding = false;
                    this.$notify.error({
                        title: '提交失败',
                        message: data.msg
                    });
                }
            }, response => {
                this.$notify.error({
                    title: '网络错误',
                    message: '网络错误'
                });
                this.loding = false;
            })
           


        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        delectdata(item) {
            var index = this.bill.indexOf(item)
            if (index !== -1) {
                this.bill.splice(index, 1)
            }
        },
        adddata() {
            if (this.addtime == "") {
                this.$alert('请先选择日期', '提示', {
                    confirmButtonText: '确定',
                });
            } else {
                var data = this.addtime;
             
                var month = data.getMonth() + 1;
              
                var strDate = data.getDate();
                var year = data.getFullYear();
                var time = year + "-" + month + "-" + strDate;
                this.bill.push({
                    BILL_DATA_ID: getid.getid(),
                    BILL_DATA_DATA: data,
                    show: time,
                    BILL_DATA_DETAIL: []
                });
                this.addtime = "";
            }
        }
    },
    activated() {
        this.bill.splice(0, this.bill.length);
        this.$http.get("Bill/" + this.$route.query["id"]).then(response => {
            var data = response.body;
            if (data.code == 1) {
                //将所有 状态改为正常 bill_data_detail_state
                var billdata = data.result[0].BILL_DATA;
                for (var i = 0; i < billdata.length; i++) {
                    var detailList = billdata[i].BILL_DATA_DETAIL;
                    for (var k = 0; k < detailList.length; k++) {
                        detailList[k].BILL_DATA_DETAIL_STATE = "正常";
                    }
                }
                this.$store.commit('changer', billdata)
                this.BILL_ID = data.result[0].BILL_ID;
                this.file = data.result[0].BILL_FILE;
                this.BILL_STATE = "";
                this.BILL_WHY = data.result[0].BILL_WHY;
                this.BILL_DISEASE = data.result[0].BILL_DISEASE;
                this.BILL_DISEASEDETAIL = data.result[0].BILL_DISEASEDETAIL;
                this.BILL_HISPOTAL = data.result[0].BILL_HISPOTAL;

            } else {

            }

        }, response => {
            this.$notify.error({
                title: '网络错误',
                message: '网络错误'
            });
            this.loding = false;
        });


    }

}
</script>